from django import forms
from django.forms.models import modelformset_factory
from django.conf import settings
from garetjax.forms.fields import DirectoryPathField
from garetjax.gallery.models import Set, Photo
from django.utils.translation import ugettext_lazy as _


PHOTOS_UPLOAD_PATH = getattr(settings, 'PHOTOS_UPLOAD_PATH', settings.MEDIA_ROOT)

class AlbumImportForm(forms.ModelForm):
    DIRECTORY_REGEX = r'^[^.]'
    
    album_folder = DirectoryPathField(PHOTOS_UPLOAD_PATH, match=DIRECTORY_REGEX,
            help_text="Cartella contenente le foto dell'album da importare. Questa "
            "cartella si trova all'indirizzo <tt>%s</tt> del filesystem locale "
            "del server" % PHOTOS_UPLOAD_PATH, label=_('Cartella da importare'))
    
    class Meta:
        model = Set

class SetEditForm(forms.ModelForm):
    class Meta:
        model = Set

PhotoFormset = modelformset_factory(Photo, exclude=('set', 'photo'), extra=0)